//
//  SVProgressHUD+YHExtension.swift
//  Adorbee
//
//  Created by amovision on 2024/11/28.
//

import UIKit
#if canImport(SVProgressHUD)
import SVProgressHUD
#endif
#if canImport(Toast)
import Toast
#endif

#if canImport(SVProgressHUD)
public func ShowHUD(_ status: String? = nil, delay: TimeInterval = 10, block: YHVoidBlock? = nil) {
  SVProgressHUD.show(withStatus: (status?.isEmpty ?? true) ?nil : status)
  if delay > 0 {
    DelayPerformer.shared.perform(withIdentifier: ObjectIdentifier(SVProgressHUD.self), delay: delay) {
      block?()
      SVProgressHUD.dismiss()
    }
  }
}

public func HideHUD() {
  DelayPerformer.shared.cancel(withIdentifier: ObjectIdentifier(SVProgressHUD.self))
  SVProgressHUD.dismiss()
}

public func MakeHUD(_ status: String, success: Bool, delay: TimeInterval = 2) {
  if success {
    SVProgressHUD.showSuccess(withStatus: status)
  } else {
    SVProgressHUD.showError(withStatus: status)
  }
  SVProgressHUD.dismiss(withDelay: delay)
}
#endif

#if canImport(Toast)
public func MakeToast(_ msg: String, position: CSToastPosition = .center, duration: TimeInterval = 2) {
  AsyncOnMain {
    YHKeyWindowView?.makeToast(msg, duration: duration, position: position)
  }
}
#endif
